/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.modules.drawer.dynamic;

import org.anderground.core.model.Transfer;
import org.anderground.core.model.Tunnel;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
class SimpleBacillus extends Bacillus {

	@SuppressWarnings("unused")
	private Road road;

	/**
	 * 
	 * @param road
	 * @param evenAmoeba
	 * @param oddAmoeba
	 */
	public SimpleBacillus(Road road, SimpleAmoeba evenAmoeba,
			SimpleAmoeba oddAmoeba) {
		this.road = road;
		this.evenAmoeba = evenAmoeba;
		this.oddAmoeba = oddAmoeba;
		evenAmoeba.addNeighborPrimitive(oddAmoeba, this);
		oddAmoeba.addNeighborPrimitive(evenAmoeba, this);
		road.addSimpleBacillus(this);
	}

	public void addTransfer(SimpleAmoeba fromAmoeba,
			SimpleAmoeba toAmoeba, Transfer transfer) {

		for (TransferPart part : transferParts) {
			if (part.opposite == (fromAmoeba != evenAmoeba)) {
				return;
			}
		}
		TransferPart part = new TransferPart();
		part.opposite = fromAmoeba != evenAmoeba;
		part.transfer = transfer;

		transferParts.add(part);
		transfersSize++;

	}

	public void addTunnel(SimpleAmoeba fromAmoeba, SimpleAmoeba toAmoeba,
			Tunnel tunnel) {

		for (TunnelPart part : tunnelParts) {
			if (part.tunnel.getLine() == tunnel.getLine()) {
				part.singleSide = false;
				return;
			}
		}
		TunnelPart part = new TunnelPart();
		part.opposite = fromAmoeba != evenAmoeba;
		part.color = tunnel.getLine().getColor();
		part.tunnel = tunnel;

		tunnelParts.add(part);
		tunnelsSize++;

	}

}
